/*
 * BDC.h
 *
 *  Created on: 2025/2/14
 *      Author: doititit
 */
#ifndef BDC_H_
#define BDC_H_
#include "zf_common_headfile.h"
#include "stdint.h"
#include "DSPTool.h"
#include "PIDLib.h"

#define BDC_2PI 6.28318530718f
typedef enum
{
    BDC_Initilize   = 0,
    BDC_STOP        = 1,
    BDC_RUN         = 2,
    BDC_Clibr       = 3,
} BDC_State_TypeDef; 
typedef struct _bdc_HardParam
{
    int8_t Dir;
    float Voltage_power_supply;
    float Voltage_limit;
    float voltage_deadband;

    float I_amps;
    float I_offset;
}BDC_HardParam_TypeDef;

typedef struct _bdc_DynaParam
{
    float Speed;
    float SmoothSpeed;
    float Current;
}BDC_DynaParam_TypeDef;

typedef struct _bdc_SetParam
{
    float Speed;
    float Voltage;
    float Current;
}BDC_SetParam_TypeDef;

typedef struct _bdc_LPF
{
    DSP_LPF_TypeDef Speed;
    DSP_LPF_TypeDef SmoothSpeed;
    DSP_LPF_TypeDef Current;
}BDC_LPF_TypeDef;

typedef struct _bdc_Func
{
    float (*GetSpeed)(void);
    float (*GetADC_I)(void);
    void (*SetDuty)(float Duty);
}BDC_Func_TypeDef;

typedef struct _bdc
{
    float ExcuteTime;
    BDC_State_TypeDef State;
    BDC_HardParam_TypeDef HardParam;
    BDC_DynaParam_TypeDef DynaParam;
    BDC_SetParam_TypeDef SetParam;
    BDC_LPF_TypeDef Lpf;
    PidStruct Current_Loop;
    PidStruct Speed_Loop;
    BDC_Func_TypeDef Func;
}BDC_TypeDef;

void BDC_GetCurrent(BDC_TypeDef *_bdc ,uint8_t lpf);
void BDC_GetSpeed(BDC_TypeDef *_bdc ,uint8_t lpf);

void BDC_SetVoltage(BDC_TypeDef *_bdc, float voltage);
void BDC_CurrentLoop(BDC_TypeDef *_bdc);
void BDC_SpeedLoop(BDC_TypeDef *_bdc);
void BDC_CurrentPidParCalc(PidParam *_pidparam, float L, float R, float ratio);

void BDC_DefaultInit(BDC_TypeDef *_bdc);




#endif
